<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="/js/jquery-3.5.1.min.js"></script>
    <script src="/js/popper.min.js"></script>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link href="/layui/css/layui.css" rel="stylesheet">
    <script src="/layui/layui.js"></script>

    <script src="/js/bootstrap.min.js"></script>
    <link href="/summernote-0.9.0/summernote-bs4.min.css" rel="stylesheet">
    <script src="/summernote-0.9.0/summernote-bs4.min.js"></script>
    <title>添加资讯</title>
    <style>
        body {
            padding: 20px;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .btn-submit {
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div class="container">
    <form id="addNewsForm" method="post">
        <div class="form-group">
            <label for="title">标题</label>
            <input type="text" class="form-control" id="question" name="question" value="{$detail.question}" required>
        </div>
        
         <div class="form-group">
            <label for="title">选项A</label>
            <input type="text" class="form-control" id="option_a" name="option_a" value="{$detail.option_a}" required>
        </div>
        
         <div class="form-group">
            <label for="title">选项B</label>
            <input type="text" class="form-control" id="option_b" name="option_b" value="{$detail.option_b}" required>
        </div>
        <input type="hidden" name="id"  id="id" value="{$detail.id}">
        <button type="submit" class="btn btn-primary btn-submit">编辑题目</button>
    </form>
</div>

<script>
    layui.use('form', function () {
            var form = layui.form;

        });
        $('#addNewsForm').on('submit', function(e) {
            e.preventDefault();
            var title = $('#title').val();
            var id = $('#id').val();
            var content = $('#summernote').summernote('code');

            $.ajax({
                url: '/admins/topic/edit',
                type: 'POST',
                data:  $(this).serialize(),
                success: function(response) {
                    if (response.code === 0) {
                        layer.msg("编辑成功", {icon: 1, shade: 0.5});
                        setTimeout(function() {
                            // 刷新父页面的列表
                            window.parent.location.reload();
                            // 关闭 iframe
                            // location.reload(); 

                            // window.parent.closeAddNewsIframe();
                        }, 1000);

                    } else {
                        alert('保存失败：' + response.msg);
                    }
                },
                error: function() {
                    alert('保存失败，请稍后重试');
                }
            });
        });

</script>
</body>
</html>